<template>
	<view>
		<topbar title="发布广告" background="background:#FFDE21"></topbar>
		<view class="content">
			<view class="dis_f_co top">
				<view class="title">设置</view>
				<view class="dis_f_l_c">
					<view class="bt">红包总额</view>
					<view class="text">*</view>
					<u-input type="number" placeholder="请输入红包总额" v-model="j_e" @input="onInput"></u-input>
				</view>
				<view class="dis_f_l_c">
					<view class="bt">红包个数</view>
					<view class="text">*</view>
					<u-input type="number" placeholder="请输入红包个数" v-model="num"></u-input>
				</view>
			</view>
			<view class="btn dis_f_sb_c">
				<view style="font-size: 32rpx;color: #E23C63;" class="font_bold">￥{{j_e2}}</view>
				<view class="right dis_f_c_c" @click="submit">支付发布</view>
			</view>
		</view>
		<u-keyboard default="" ref="uKeyboard" mode="number" :mask="true" :mask-close-able="false" :dot-enabled="false"
			v-model="show" :safe-area-inset-bottom="true" :tooltip="false" @change="onChange" @backspace="onBackspace">
			<view>
				<view class="u-text-center u-padding-20 money">
					<text>{{j_e}}</text>
					<text class="u-font-20 u-padding-left-10">元</text>
					<view class="u-padding-10 close" data-flag="false" @tap="showPop(false)">
						<u-icon name="close" color="#333333" size="28"></u-icon>
					</view>
				</view>
				<view class="u-flex u-row-center">
					<u-message-input mode="box" :maxlength="6" :dot-fill="true" v-model="password"
						:disabled-keyboard="true" @finish="finish"></u-message-input>
				</view>
				<view class="u-text-center u-padding-top-10 u-padding-bottom-20 tips">支付键盘</view>
			</view>
		</u-keyboard>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				action: 'http://www.example.com/upload',
				fileList: [],
				text: '',
				yes: false,
				type: 4,
				j_e: '',
				j_e2: '0',
				num: '',
				pic: '',
				red: 1,
				show: false,
				password: ''
			};
		},
		watch: {

		},
		onLoad(e) {
			// console.log(e)
			this.text = e.content
			this.type = e.cate
			this.pic = e.pic
			this.red = e.red

		},
		methods: {
			onInput() {
				this.j_e2 = this.j_e
			},
			onChange(val) {
				// console.log(this.password)
				if (this.password.length < 6) {
					this.password += val;

				}

				if (this.password.length >= 6) {
					console.log(this.password)
					this.$.ajax(1, 'post', 'index/checkpaypassword', {
						uid: uni.getStorageSync('uid'),
						token: uni.getStorageSync('token'),
						password: this.password,
					}, (res) => {
						console.log(res)
						if (res.code == 1) {
							this.$.ajax(1, 'post', 'index/setguang', {
								uid: uni.getStorageSync('uid'),
								token: uni.getStorageSync('token'),
								content: this.text,
								cate: this.type,
								pic: this.pic,
								red: this.red,
								rednum: this.num,
								redallmoney: this.j_e
							}, (res) => {
								console.log(res)
								if (res.code == 1) {
									this.show = false
									this.password = ''
									this.$.ti_shi(res.msg)
									setTimeout(() => {
										uni.switchTab({
											url: '/pages/index/index'
										})
									}, 1000)

								} else {
									this.$.ti_shi(res.msg)
								}

							})
							// this.$.ti_shi(res.msg)
						} else {
							this.password = ''
							this.$.ti_shi(res.msg)
						}

					})
					// this.pay();
				}
			},
			onBackspace(e) {
				if (this.password.length > 0) {
					this.password = this.password.substring(0, this.password.length - 1);
				}
			},
			showPop(flag = true){
				this.password = '';
				this.show = flag;
			},
			submit() {

				this.$.ajax(1, 'post', 'index/checktokens', {
					uid: uni.getStorageSync('uid'),
					token: uni.getStorageSync('token')
				}, (res) => {
					console.log(res)
					if (res.code == 9) {
						this.$.ti_shi('token已过期，请重新登陆')
						uni.clearStorageSync()
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 1000)
						return;
					} else {
						if (this.j_e == '') {
							this.$.ti_shi('请输入红包总额')
							return;
						}
						if (this.num == '') {
							this.$.ti_shi('请输入红包个数')
							return;
						}


						this.$.ajax(1, 'post', 'index/getuser', {
							uid: uni.getStorageSync('uid'),
							token: uni.getStorageSync('token'),
						}, (res) => {
							console.log(res)
							if (res.code == 1) {
								if (res.userinfo.paypassword == '') {
									this.$.ti_shi('您暂未设置密码，请前去设置')
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages/mine/zf_mm'
										})
									}, 1000)

								} else {
									this.show = true;
								}

								// this.show = false
								// this.password = ''
								// 


							} else {
								this.$.ti_shi(res.msg)
							}

						})


						//http://localhost:8080/#/pages/guang_gao/part2?content=asdadsa&cate=5&pic=158&red=1


					}
				})

			}
		}
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		top: calc(var(--status-bar-height) + 88rpx);
		z-index: 998;
		position: absolute;
		padding: 36rpx 24rpx;

		.top {
			width: 100%;
			margin-bottom: 12rpx;
			padding: 36rpx 24rpx;
			background-color: #fff;
			border-radius: 20rpx;
			box-shadow: 0rpx 6rpx 24rpx rgba(34, 34, 34, 0.05);

			.title {
				font-size: 28rpx;
				line-height: 40rpx;
				color: #222222;
				margin-bottom: 24rpx;
			}

			.bt {
				font-size: 28rpx;
				line-height: 40rpx;
			}

			.text {
				color: #E23C63;
				margin-left: 12rpx;
				margin-right: 48rpx;
			}
		}

		.btn {
			position: fixed;
			bottom: 84rpx;
			height: 98rpx;
			width: 702rpx;
			left: 24rpx;

			.right {
				width: 444rpx;
				height: 98rpx;
				color: #fff;
				border-radius: 50rpx;
				background-color: #E23C63;
			}
		}
	}

	.money {
		font-size: 80rpx;
		color: $u-type-warning;
		position: relative;

		.close {
			position: absolute;
			top: 20rpx;
			right: 20rpx;
			line-height: 28rpx;
			font-size: 28rpx;
		}
	}

	.tips {
		color: $u-tips-color;
	}

	.zf_btn {
		color: #fff;
		background-color: #E23C63;
		border-radius: 20rpx;
		width: 100%;
		height: 88rpx;
	}
</style>
